package com.ruiysoft.service.integral.consts;

import java.util.Objects;

public enum TradeType {
    RECHARGE(1, "充值"), CONSUME(2, "消费"), REFUND(3, "退款");
    private int index;
    private String name;

    private TradeType(int index, String name) {
        this.index = index;
        this.name = name;
    }

    public static String getName(int index) {
        for (TradeType s : TradeType.values()) {
            if (Objects.equals(s.getIndex(),index)) {
                return s.getName();
            }
        }
        return null;
    }

    public static TradeType getEnum(int index) {
        for (TradeType s : TradeType.values()) {
            if (Objects.equals(s.getIndex(),index)) {
                return s;
            }
        }
        return null;
    }

    public boolean isAdd() throws RuntimeException{
        switch (this) {
            case RECHARGE:
            case REFUND:
                return true;
            case CONSUME:
                return false;
            default:
                throw new RuntimeException("积分处理类型不存在"+this.getIndex());
        }
    }

    public boolean isRefund() throws RuntimeException{
        switch (this) {
            case REFUND:
                return true;
            case RECHARGE:
            case CONSUME:
                return false;
            default:
                throw new RuntimeException("积分处理类型不存在"+this.getIndex());
        }
    }
    public int getIndex() {
        return this.index;
    }

    public String getName() {
        return this.name;
    }
}
